// 引入路由组件
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
// 引入二级路由组件
import MyOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'

// 路由配置信息
export default [
  {
    path: '/center',
    component: Center,
    meta:{show:true},
    // 二级路由组件
    children:[
      {
        path:'myorder',
        component:MyOrder,
      },
      {
        path:'grouporder',
        component:GroupOrder
      },
      {
        path:'/center',
        redirect:'/center/myorder'
      }
    ]
  },
  {
    path: '/paysuccess',
    component: PaySuccess,
    meta:{show:true},
  },
  {
    path: '/pay',
    component: Pay,
    meta:{show:true},
    beforeEnter: (to, from, next) => {
      // 去交易页面，必须是从购物车而来
      if(from.path=="/trade"){
        next();
      }else{
        // 其他路由组件而来停留在当前
        next(false)
      }
    }
  },
  {
    path: '/trade',
    component: Trade,
    meta:{show:true},
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 去交易页面，必须是从购物车而来
      if(from.path=="/shopcart"){
        next();
      }else{
        // 其他路由组件而来停留在当前
        next(false)
      }
    }
  },
  {
    path: '/shopcart',
    component: ()=>import("@/pages/ShopCart"),
    meta:{show:true},
  },
  {
    path: '/addcartsuccess',
    component: ()=>import("@/pages/AddCartSuccess"),
    meta:{show:true},
    name:'addcartsuccess'
  },
  {
    path: '/detail/:skuId',
    component: ()=>import("@/pages/Detail"),
    meta:{show:true}
  },
  {
    path: '/home',
    component: ()=>import("@/pages/Home"),
    meta:{show:true}
  },
  {
    // 实现params参数可传可不传参
    path: '/search/:keyword?',
    component: ()=>import('@/pages/Search'),
    meta:{show:true},
    name: 'search'
  },
  {
    path: '/login',
    component: ()=>import("@/pages/Login"),
    // 不显示footer的路由
    meta:{show:false}
  },
  {
    path: '/register',
    component: ()=>import("@/pages/Register"),
    // 不显示footer的路由
    meta:{show:false}
  },
  {
    // 重定向：在项目跑起来的时候，访问/，立即将其定向至首页
    path: '*',
    redirect: '/home'
  }
]